import Vue from 'vue'
import App from './App.vue'
import Storage from 'vue-ls'
import router from '@/router'
import store from './store/'

import { VueAxios } from "@lone/lone-vue/src/utils/request"

import Antd from 'ant-design-vue'
import Viser from 'viser-vue'
import 'ant-design-vue/dist/antd.less';  // or 'ant-design-vue/dist/antd.less'

import '@/permission' // permission control
import '@lone/lone-vue/src/utils/filter' // base filter
import '@lone/lone-vue/src/utils/functionAop'
import '@lone/lone-vue/src/components/jeecg/JVxeTable/install'
import '@lone/lone-vue/src/components/JVxeCells/install'

import Print from 'vue-print-nb-jeecg'
/*import '@babel/polyfill'*/

require('@jeecg/antd-online-mini')
require('@jeecg/antd-online-mini/dist/OnlineForm.css')

import echarts from 'echarts'
Vue.prototype.$echarts = echarts

import {
  ACCESS_TOKEN,
  CURRENT_ROLE,
  CURRENT_DEPART,
  CURRENT_DEPART_NAME,
  CURRENT_ROLE_NAME,
  DEFAULT_COLOR,
  DEFAULT_THEME,
  DEFAULT_LAYOUT_MODE,
  DEFAULT_COLOR_WEAK,
  SIDEBAR_TYPE,
  DEFAULT_FIXED_HEADER,
  DEFAULT_FIXED_HEADER_HIDDEN,
  DEFAULT_FIXED_SIDEMENU,
  DEFAULT_CONTENT_WIDTH_TYPE,
  DEFAULT_MULTI_PAGE
} from "@/store/mutation-types"

import config from '@/defaultSettings'

import JDictSelectTag from '@lone/lone-vue/src/components/dict/index.js'
import hasPermission from '@lone/lone-vue/src/utils/hasPermission'
import vueBus from '@lone/lone-vue/src/utils/vueBus';
import JeecgComponents from '@lone/lone-vue/src/components/jeecg/index'
import '@lone/lone-vue/src/utils/functionAop'
import loneconst from '@lone/lone-vue/src/const/loneconst'
import baseconst from '@/const/baseconst'

import '@/assets/less/JAreaLinkage.less'
import VueAreaLinkage from 'vue-area-linkage'

Vue.config.productionTip = false
Vue.use(loneconst);
Vue.use(baseconst)
Vue.use(Storage, config.storageOptions)
Vue.use(Antd)
Vue.use(VueAxios, router)
Vue.use(Viser)
Vue.use(hasPermission)
Vue.use(JDictSelectTag)
Vue.use(Print)
Vue.use(vueBus);
Vue.use(JeecgComponents);
Vue.use(VueAreaLinkage);

const formatDate = function() {
  let date = new Date();
  let year = date.getFullYear(); // 年
  let month = date.getMonth() + 1; // 月
  let day = date.getDate(); // 日
  let hour = date.getHours(); // 时
  hour = hour < 10 ? "0" + hour : hour; // 如果只有一位，则前面补零
  let minute = date.getMinutes(); // 分
  minute = minute < 10 ? "0" + minute : minute; // 如果只有一位，则前面补零
  let second = date.getSeconds(); // 秒
  second = second < 10 ? "0" + second : second; // 如果只有一位，则前面补零
  return `${year}-${month}-${day} ${hour}:${minute}:${second}}`;
}
Vue.prototype.$formatDate = formatDate;

const copyProperties = function(form, source, goal, dataSource){
  if(source) {
    for (let p in source) {
      if (source[p] instanceof Array) {
        const ps = source[p];
        for (let pp in ps) {
          let newData = ps[pp];
          dataSource.push(newData);
        }
      } else {
        let field = {};
        field[p] = source[p];
        if (goal && goal[p] && !source[p]) {
          field[p] = goal[p];
        }
        form.setFieldsValue(field)
      }
    }
  }
}

Vue.prototype.$copyProperties = copyProperties;

const clone = function(source, dest, sourceProperties, destProperties) {
  for(let p in dest){
    let idx = -1;
    if((idx = destProperties.indexOf(p)) != -1){
        source[sourceProperties[idx]] = dest[p];
    }else{
      source[p] = dest[p];
    }
  }
  return source;
}

Vue.prototype.$clone = clone;

new Vue({
  router,
  store,
  mounted () {
    store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
    store.commit('TOGGLE_THEME', config.navTheme)
    store.commit('TOGGLE_LAYOUT_MODE', config.layout)
    store.commit('TOGGLE_FIXED_HEADER', config.fixedHeader)
    store.commit('TOGGLE_FIXED_SIDERBAR', config.fixSiderbar)
    store.commit('TOGGLE_CONTENT_WIDTH', config.contentWidth)
    store.commit('TOGGLE_FIXED_HEADER_HIDDEN', config.autoHideHeader)
    store.commit('TOGGLE_WEAK', config.colorWeak)
    store.commit('TOGGLE_COLOR', config.primaryColor)
    store.commit('SET_MULTI_PAGE',config.multipage)


    // store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, config.navTheme))
    // store.commit('TOGGLE_LAYOUT_MODE', Vue.ls.get(DEFAULT_LAYOUT_MODE, config.layout))
    // store.commit('TOGGLE_FIXED_HEADER', Vue.ls.get(DEFAULT_FIXED_HEADER, config.fixedHeader))
    // store.commit('TOGGLE_FIXED_SIDERBAR', Vue.ls.get(DEFAULT_FIXED_SIDEMENU, config.fixSiderbar))
    // store.commit('TOGGLE_CONTENT_WIDTH', Vue.ls.get(DEFAULT_CONTENT_WIDTH_TYPE, config.contentWidth))
    // store.commit('TOGGLE_FIXED_HEADER_HIDDEN', Vue.ls.get(DEFAULT_FIXED_HEADER_HIDDEN, config.autoHideHeader))
    // store.commit('TOGGLE_WEAK', Vue.ls.get(DEFAULT_COLOR_WEAK, config.colorWeak))
    // store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
    // store.commit('SET_MULTI_PAGE',Vue.ls.get(DEFAULT_MULTI_PAGE,config.multipage))

    store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
    store.commit('SET_CURRENT_ROLE', Vue.ls.get(CURRENT_ROLE))
    store.commit('SET_CURRENT_DEPART', Vue.ls.get(CURRENT_DEPART))
    store.commit('SET_CURRENT_DEPART_NAME', Vue.ls.get(CURRENT_DEPART_NAME))
    store.commit('SET_CURRENT_ROLE_NAME', Vue.ls.get(CURRENT_ROLE_NAME))
  },
  render: h => h(App)
}).$mount('#app')
